bool match(string str, string pattern) {
    int m = str.size();
    int n = pattern.size();
    str = ' ' + str;
    pattern = ' ' + pattern;
    vector<vector<bool>> dp(m + 1, vector<bool>(n + 1));
    dp[0][0] = true;
    for (int x = 2; x <= n; x += 2)
        if (pattern[x] == '*') dp[0][x] = true;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (pattern[j] == '*') dp[i][j] = dp[i][j - 2] || (pattern[j - 1] == '.' || pattern[j - 1] == str[i]) && dp[i - 1][j];
            else
                dp[i][j] = (pattern[j] == str[i] || pattern[j] == '.') && dp[i - 1][j - 1];
        }
    }
    return dp[m][n];

}